package com.tp1.log121.formes;

import java.awt.Color;
import java.awt.Graphics2D;

import com.tp1.log121.main.ApplicationSupport;
import com.tp1.log121.main.ChaineDecortiquee;

public class Ovale extends Forme {

	private final Color COULEUR_CERCLE = Color.BLUE;
	private final Color COULEUR_OVALE = Color.CYAN;

	private int x;
	private int y;
	private int l;
	private int h;

	public Ovale(ChaineDecortiquee cd) {
		super(cd);

		l = 2 * Integer.parseInt(informations[2]);

		if (nomForme.equals(FormesNoms.OVALE)) {
			h = 2 * Integer.parseInt(informations[3]);
			couleur = COULEUR_OVALE;
			priorite = Integer.parseInt(ApplicationSupport
					.getResource("app.frame.shape.priority.oval"));
		} else {
			h = l;
			couleur = COULEUR_CERCLE;
			priorite = Integer.parseInt(ApplicationSupport
					.getResource("app.frame.shape.priority.cercle"));
		}
	}

	@Override
	public void dessinerFormeOriginales(Graphics2D g2d) {
		int rayonV;

		if (nomForme.equals(FormesNoms.OVALE)) {
			rayonV = Integer.parseInt(informations[3]);
		} else {
			rayonV = Integer.parseInt(informations[2]);
		}

		x = Integer.parseInt(informations[0])
				- Integer.parseInt(informations[2]);
		y = Integer.parseInt(informations[1]) + rayonV;
		
		dessinerForme(g2d);
	}

	@Override
	public void dessinerFormeModifiees(Graphics2D g2d, int x, int y) {
		this.x = x;
		this.y = y;

		dessinerForme(g2d);
	}

	@Override
	public int getAire() {
		if (nomForme.equals(nomForme.equals(FormesNoms.OVALE))) {
			return (int) (Math.PI * (l/2) * (h/2));
			
		} else {
			return (int) (Math.PI * Math.pow((l / 2), 2));
		}
		
	
	}

	@Override
	public int getDistanceMaximale() {
		if (Integer.valueOf(l).compareTo(Integer.valueOf(h)) == 1) {
			return l;
		} else {
			return h;
		}
	}

	@Override
	public int getLargeur() {
		return l;
	}

	@Override
	public int getHauteur() {
		return h;
	}

	@Override
	protected void dessinerForme(Graphics2D g2d) {
		g2d.setColor(Color.BLACK);
		g2d.drawOval(x, y, l, h);
		g2d.setColor(couleur);
		g2d.fillOval(x, y, l, h);
	}
}
